package com.devicemantra.coordinate.dataobjects;

import javax.jdo.annotations.*;


import java.util.*;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable ="true")
public class CAuthMobileMessage 
{
	@PrimaryKey
    @Persistent //(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private String mMessageKey;
	
	@Persistent
	private String mAuthCode;
	
	@Persistent
	private String mAuthMobileNumber;
	
	@Persistent
	private String mAuthEmailId;
	
	@Persistent
	private String mAuthUserName;
	@Persistent
	private boolean mIsAuthPassed= false;
	@Persistent
	public  int  mCallState = 1;
	
	public CAuthMobileMessage()
	{
		mMessageKey = Long.toString(new Random().nextLong());		
		mCallState = 0;
	}
	
	public void setAuthCode(String pAuthCode) {
		mAuthCode = pAuthCode;
	}
	
	public String getAuthCode() {
		return mAuthCode;
	}
	
	public void markAsAuthPassed()
	{
		mIsAuthPassed = true;
		mCallState = 2;
	}
	
	public void markAsAuthFailed()
	{
		mIsAuthPassed = false;
		mCallState = 3;
	}
	
	public String getMessageId()
	{
		return mMessageKey;
	}

	public void setAuthMobileNumber(String pAuthMobileNumber) {
		mAuthMobileNumber = pAuthMobileNumber;
	}

	public String getAuthMobileNumber() {
		return mAuthMobileNumber;
	}

	public void setAuthEmailId(String pAuthEmailId) {
		mAuthEmailId = pAuthEmailId;
	}

	public String getAuthEmailId() {
		return mAuthEmailId;
	}

	public void setAuthUserName(String pAuthUserName) {
		this.mAuthUserName = pAuthUserName;
	}

	public String getAuthUserName() {
		return mAuthUserName;
	}
	
	public String getStatus()
	{
		/* if(mIsAuthPassed)
			return "PASSED";
		else
			return "FAILED"; */
		
		if((mCallState != 2) && (mCallState != 3)){
			return "TRYING";
		}
		else if(mCallState == 2)
			return "PASSED";
		else if(mCallState == 3)
			return "FAILED";
		else return null;
	}
	
	public int getState() {
		return mCallState;
	}
	
	public void setCallState(int pState) {
		mCallState = pState;
	}

	public String getCallState() {
		// TODO Auto-generated method stub
		String lStr = null;
		switch(mCallState) {
		case 1:
				lStr = "Idle..";
				break;
		case 2:
			lStr = "Connected..";
			break;
		case 3:
			lStr = "Authenticating..";
			break;
		default:
			lStr = "Something wrong";
				
		}
		return lStr;
	}
	
}
